package com.af.security.auth.phone;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author : zhenyun.su
 * @comment :
 *   String phone 手机号
 *   String verificationCode  短信验证码
 *   LocalDateTime createdDate; 创建时间
 *   String nonce;  随机数
 * @since : 2020-9-22
 */

public class PhoneUserDetails implements Serializable {
    private String phone;
    private String verificationCode;
    private LocalDateTime createdDate;
    private String nonce;

    public boolean expired() {
        return  LocalDateTime.now().isAfter(createdDate);
    }

    public static PhoneUserDetails of(String phone, String verificationCode, LocalDateTime createdDate, String nonce){
        PhoneUserDetails phoneUserDetails = new PhoneUserDetails();
        phoneUserDetails.setPhone(phone);
        phoneUserDetails.setVerificationCode(verificationCode);
        phoneUserDetails.setCreatedDate(createdDate);
        phoneUserDetails.setNonce(nonce);
        return phoneUserDetails;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getVerificationCode() {
        return verificationCode;
    }

    public void setVerificationCode(String verificationCode) {
        this.verificationCode = verificationCode;
    }

    public LocalDateTime getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(LocalDateTime createdDate) {
        this.createdDate = createdDate;
    }

    public String getNonce() {
        return nonce;
    }

    public void setNonce(String nonce) {
        this.nonce = nonce;
    }

    @Override
    public String toString() {
        return "PhoneUserDetails{" +
                "phone='" + phone + '\'' +
                ", verificationCode='" + verificationCode + '\'' +
                ", createdDate=" + createdDate +
                ", nonce='" + nonce + '\'' +
                '}';
    }
}
